const totop = () => {
    window.scrollTo({
        top: 0,
        behavior: "smooth",
    });
};


/**
 * 动态引入css
 * @param {url} url | css地址
 */
function importCss(url) {

    if (url) {
        let cssLink = document.createElement('link');
        cssLink.setAttribute("rel", "stylesheet")
        cssLink.setAttribute("type", "text/css")
        cssLink.setAttribute("href", url)

        document.head.appendChild(cssLink);
    }
}
/**
 * 移除动态加载的css
 * @param {file} file | css文件名
 */
function removeStyles(file) {
    // console.log("将要删除的css：" + file)
    if (file) {
        var filename = file;
        var targetelement = "link";
        var targetattr = "href";
        var allsuspects = document.getElementsByTagName(targetelement);
        for (var i = allsuspects.length; i >= 0; i--) {
            if (allsuspects[i] && allsuspects[i].getAttribute(targetattr) != null && allsuspects[i].getAttribute(
                targetattr).indexOf(filename) != -1) {
                allsuspects[i].parentNode.removeChild(allsuspects[i])
            }
        }
    }
}
